package com.gnerv.sylvanas.framework.autoconfigure.security;

import com.gnerv.sylvanas.authentication.security.autoconfigure.SylvanasSecurityAutoConfiguration;
import com.gnerv.sylvanas.authentication.security.tool.SecurityTools;
import com.gnerv.sylvanas.business.manage.autoconfigure.FrameworkManageAutoConfiguration;
import com.gnerv.sylvanas.framework.core.BaseAccountPassword;
import com.gnerv.sylvanas.framework.core.BaseCurrentAccount;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.security.crypto.password.PasswordEncoder;


/**
 * @author Gnerv LiGen
 */
@Slf4j
@AutoConfiguration
@ComponentScan(value = "com.gnerv.sylvanas.framework.autoconfigure")
@AutoConfigureBefore({FrameworkManageAutoConfiguration.class, SylvanasSecurityAutoConfiguration.class})
public class SylvanasSecurityManageAutoConfiguration {

    @Bean
    @ConditionalOnBean(value = {PasswordEncoder.class})
    public BaseAccountPassword baseAccountPassword(PasswordEncoder passwordEncoder) {
        return new BaseAccountPassword(){
            @Override
            public String encrypt(String source) {
                return passwordEncoder.encode(source);
            }
        };
    }



}
